/**
 *用户标记
 * 必要参数：UID
 *          Title
 *          Context
 *          lat
 *          lng
 */
package Servlet;

import Acquaintance.IAMark;
import Control.CAccountManage;
import Entity.ELocation;
import Entity.EMark;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 *增加用户标记点<br>
  *必要参数：UID<br>
 *          Title<br>
 *          Context<br>
 *          lat<br>
 *          lng<br>
 * @author Administrator
 */
public class addMark extends HttpServlet {

    /**
     * Processes requests for both HTTP
     * <code>GET</code> and
     * <code>POST</code> methods.
     *
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    protected void processRequest(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        request.setCharacterEncoding("UTF-8");
   response.setContentType("text/html;charset=UTF-8");
        PrintWriter out = response.getWriter();
        try {
 
            String Lat=request.getParameter("lat");
            String Lng=request.getParameter("lng");
            String UID=request.getParameter("UID");
            String Context=request.getParameter("Context");
            String Title=request.getParameter("Title");
            
            int uID = Integer.parseInt(UID);
            double lat=Double.parseDouble(Lat);
            double lng=Double.parseDouble(Lng);
            

             
             IAMark mark=new EMark();
             mark.setUID(uID);
             mark.setContext(Context);
             mark.setTitle(Title);
             mark.setLocation(new ELocation(lat,lng));
             
             
             CAccountManage ca=new CAccountManage();
             if(ca.InsertMark(mark))
             {
                 out.print("Successs");
             }
             else
             {
                 out.print("Failed");
             }
            
        } finally {            
            out.close();
        }
    }

    // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
    /**
     * Handles the HTTP
     * <code>GET</code> method.
     *
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        processRequest(request, response);
    }

    /**
     * Handles the HTTP
     * <code>POST</code> method.
     *
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        processRequest(request, response);
    }

    /**
     * Returns a short description of the servlet.
     *
     * @return a String containing servlet description
     */
    @Override
    public String getServletInfo() {
        return "Short description";
    }// </editor-fold>
}
